package com.dgut.medicalsystem.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.dgut.medicalsystem.entity.FeedBack;
import com.dgut.medicalsystem.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/feed_back")
public class FeedBackController {

    @Autowired
    FeedBackService feedBackService;

    @SaCheckLogin
    @RequestMapping("/send")
    public Map<String,Object> send (@RequestBody FeedBack feedBack) throws Exception {

        Map<String,Object> map = new HashMap<>();
        System.out.println(feedBack);
        try{
            Integer id = Integer.parseInt(StpUtil.getLoginId().toString().substring(1));
            if (!id.equals(feedBack.getUid())){
                throw new Exception("用户信息不一致，请稍后重试");
            }
            else{
                if(feedBackService.send(feedBack)==1){
                    map.put("code",200);
                    map.put("msg","反馈成功");
                    return map;
                }else{
                   throw new Exception("反馈失败，请稍后重试");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception("系统错误，请稍后重试");
        }
    }
}
